import { SystemMsg } from '@entity/system_msg'
import axios from '@axios/websocket';
import { Component, Prop, Vue } from 'vue-property-decorator'

@Component
export class SystemMsgModel extends Vue {

    @Prop({
        default: () => new SystemMsg()
    })
    /** 系统消息 */
    private msg: SystemMsg;

    private get isRead(): string {
        return this.msg.read ? "已读" : "未读";
    }

    private readMsg(): void {
        if (this.msg.read) {
            return;
        }
        axios.system.doReadMsg(this.msg.id).then((res: boolean) => {
            if (res) {
                this.msg.read = true;
                this.$store.commit('addSystemMsg', this.msg);
            }
        })
    }

}